package com.fast.develop.meta.base;


import com.fast.develop.meta.base.exception.MetaException;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 莫寅
 * @createTime 2022-06-15 14:18
 * @desc：
 */
public class MetaRegistry {

    private Map<String, MetaRegistor> metaRegistors = new HashMap<>();


    public void register(MetaRegistor metaRegistor){

        String type = metaRegistor.type();

        if(metaRegistors.get(type) != null){
            throw new MetaException("元数据读取器已注册！：{}", type);
        }

        metaRegistors.put(type, metaRegistor);
    }

    public MetaRegistor getMetaRegistor(String type){
        return metaRegistors.get(type);
    }

    public Collection<MetaRegistor> getMetaRegistors(){
        return metaRegistors.values();
    }
}
